//
//  HLOAuthViewController.swift
//  MyWeiBo
//
//  Created by fannie on 16/3/21.
//  Copyright © 2016年 fannie. All rights reserved.
//

import UIKit
import SVProgressHUD

class HLOAuthViewController: UIViewController {

    override func loadView() {
        view=webview
        webview.delegate=self
    }
    
    override func viewDidLoad() {
        super.viewDidLoad()

        view.backgroundColor=UIColor.whiteColor()
        setupNavigationBar()
        
        let string:String="https://api.weibo.com/oauth2/authorize?client_id=\(client_id)&redirect_uri=\(redirect_uri)"
        let url=NSURL(string: string)
        let request=NSURLRequest(URL: url!)
        webview.loadRequest(request)
        
//        SVProgressHUD.showErrorWithStatus("正在加载")
//        SVProgressHUD.showErrorWithStatus("正在加载", maskType: SVProgressHUDMaskType.Gradient)
//        SVProgressHUD.showInfoWithStatus("正在加载", maskType: SVProgressHUDMaskType.Gradient)
        SVProgressHUD.showWithStatus("正在加载", maskType: SVProgressHUDMaskType.Gradient)
    }

    private func setupNavigationBar() {
        navigationItem.leftBarButtonItem=UIBarButtonItem(title: "填充", style: UIBarButtonItemStyle.Plain, target: self, action: "autoFill")
        navigationItem.rightBarButtonItem=UIBarButtonItem(title: "取消", style: UIBarButtonItemStyle.Plain, target: self, action: "cannel")
    }
    
    @objc private func autoFill() {
        print("tianchong")
    }
    
    @objc private func cannel() {
        navigationController?.dismissViewControllerAnimated(true, completion: nil)
    }
    
    lazy var webview:UIWebView=UIWebView()
}

extension HLOAuthViewController:UIWebViewDelegate {
    func webViewDidFinishLoad(webView: UIWebView) {
        SVProgressHUD.dismiss()
    }
}
